#!usr/bin/env python
# -*- coding:utf-8 -*-
# user nanme: Mr.zhang
# data time : 2022/8/22   5:41 下午
# project   : ding_messge.py
# IDE       : PyCharm
# email     :17600960626@163.com

import json
import os

import requests

Url = '***************1'#钉钉openapi
HEADERS = {"Content-Type": "application/json ;charset=utf-8 "}


def dev_messge(devices,files):

    mags = '💣💣监控报警💣💣️\n键盘收起了\n监控程序启动，已点击屏幕\n设备id：%s\n键盘收起次数：%s\n💣💣💣💣💣💣💣💣️'\
           % (devices,files)

    String_textMsg = {"msgtype": "text",
                      "text": {
                          "content": mags
                      },
                      "at": {
                          "atMobiles": ['+86-17600960626'],
                          "isAtAll": False
                      }
                      }
    String_textMsgs = json.dumps(String_textMsg)
    res = requests.post(Url, data=String_textMsgs, headers=HEADERS)
    return res



def un_messge(devices):
    mags = '💣💣监控报警💣💣️\n设备断开了\n监控程序启动，已对设备进行了状态标记\n设备id：%s\n💣💣💣💣💣💣💣💣️' % devices
    String_textMsg = {"msgtype": "text",
                      "text": {
                          "content": mags
                      },
                      "at": {
                          "atMobiles": ['+86-17600960626'],
                          "isAtAll": False
                      }
                      }
    String_textMsgs = json.dumps(String_textMsg)
    res = requests.post(Url, data=String_textMsgs, headers=HEADERS)
    return res



def stop_msg(devices):
    mags = '💣💣监控报警💣💣️\n测试已完成\n监控程序启动，已对设备进行了状态标记\n设备id：%s\n💣💣💣💣💣💣💣💣️' % devices
    String_textMsg = {"msgtype": "text",
                      "text": {
                          "content": mags
                      },
                      "at": {
                          "atMobiles": ['+86-17600960626'],
                          "isAtAll": False
                      }
                      }
    String_textMsgs = json.dumps(String_textMsg)
    res = requests.post(Url, data=String_textMsgs, headers=HEADERS)
    return res